#-------------------------------------------------
# - Library path -
-include ./Make.inc

ID_FORT ?= 2

SRC_PATH = ./src
INC_PATH = ./include
OBJ_PATH = ./_obj_

CCINCS 		= -I$(SRC_PATH) \
	  	  -I$(INC_PATH) \
		  -I$(METIS_INC_PATH) \
	  	  -I$(FLA_INC_PATH) \
		  -I$(LINAL_INC_PATH) 

CCDEFS 		= -D __ID_FORT__=$(ID_FORT)

ifdef CUDA_PATH
CCINCS         	+= -I$(CUDA_INC_PATH)
endif

ifdef PETSC_PATH
CCINCS         += -I$(PETSC_INC_PATH) -I$(PETSC_MPI_INC_PATH)
CCDEFS         += -D __PETSC_USE__
endif

#
CXX_WORK 	= $(CXX) $(CFLAGS) $(EXTRA_CFLAGS) \
		  $(CCINCS) $(CCDEBUG) $(CCWARN) $(CCDEFS)

# sources
SRC_FILE 	= \
		mat/linal/mat.cxx \
		mat/linal/ops.cxx \
		util/id.cxx \
		util/option.cxx \
		util/stream.cxx \
		util/util.cxx 

#		wrapper/fort/linal/method.cxx \
#		wrapper/fort/linal/solver.cxx \
#		wrapper/fort/util.cxx \
#		wrapper/fort/linal/petsc.cxx 





##INC           = $(addprefix $(INC_PATH)/,$(INC_FILE))      
SRC 		= $(addprefix $(SRC_PATH)/,$(SRC_FILE))
OBJ 		= $(addprefix $(OBJ_PATH)/,$(SRC_FILE:.cxx=.o))

# make
.PHONY : lib

lib : libuhm.a
	@echo "UHM Library is created at " $(UHM_LIB_PATH)/$<

libuhm.a : all
	@echo "Creating directory " $(UHM_LIB_PATH)
	@mkdir -p $(UHM_LIB_PATH)
	@ar cr $(UHM_LIB_PATH)/$@ $(OBJ)
	@ranlib $(UHM_LIB_PATH)/$@

all : $(OBJ_PATH)/.dummy $(OBJ)

$(OBJ_PATH)/.dummy :
	@echo "Creating directory " $(OBJ_PATH) 
	@if [ -d $(OBJ_PATH) ]; then \
		touch $@; \
	else mkdir $(OBJ_PATH); touch $@; \
	fi

$(OBJ_PATH)/%.o : $(SRC_PATH)/%.cxx
	@mkdir -p $(dir $@)
	@echo "Compiling $<"
	$(CXX_WORK) -o $@ -c $<

.PHONY : clean

clean:
	@(echo "Clean tests")
	@(echo "Clean object files and library")
	@(rm -rf $(OBJ_PATH))
	@(rm -f $(UHM_LIB_PATH)/*.a)
	@(echo "Clean misc")
	@(rm -rf ./docs)
	@(find . -iname "*~" -exec rm {} \;)
###	@(cd ./test; make clean)